package org.gaaidou.ptarmigan.springboot.core.serialize.xml;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.gaaidou.ptarmigan.springboot.core.common.Common;
import org.gaaidou.ptarmigan.springboot.core.serialize.json.ObjectMapperFactory;

@Slf4j
public final class XmlUtil {

    public static <T> T parse(String jsonString, Class<T> clazz) {
        try {
            return XmlMapperFactory.getInstance().readValue(jsonString, clazz);
        } catch (JsonProcessingException e) {
            log.warn("");
            return null;
        }
    }

    public static <T> T parse(String jsonString, TypeReference<T> typeReference) {
        try {
            return XmlMapperFactory.getInstance().readValue(jsonString, typeReference);
        } catch (JsonProcessingException e) {
            log.warn("");
            return null;
        }

    }

    public static <T> String toXmlString(T json) {
        try {
            return ObjectMapperFactory.getInstance().writeValueAsString(json);
        } catch (JsonProcessingException e) {
            log.warn("");
            return Common.EMPTY_STRING;
        }

    }


}